//
//  HCMineAppViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/21.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCMineAppViewController.h"

#import "HCMineAppView.h"

#import "HCMineAppointmentModel.h"

@interface HCMineAppViewController () <HCMineAppViewRefresh> {
    HCMineAppointmentModel *model;
    HCMineAppView *vc;
    HCPopLoadingView *popLoading;
    UITableView *tableView__;
}

@end

@implementation HCMineAppViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.textTitle = @"我的预约";
    //    [WZNetWorkStatusManager show:centerView type:WZNetWorkStatusLoadingWithImage msg:YBKLoadingText subMsg:nil offsetY:(centerView.frame.size.height - YBKAdaptiveH(120))/2.0 failClickBlock:nil];
    
    self.dataRequest.delegate = self;
    popLoading = [[HCPopLoadingView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [popLoading showAnimate];
    if ([PublicFunction isNull:HCGETUSER(@"userid")]) {
        NSLog(@"没有用户");
    }else{
        [self.dataRequest postHC_MineAppointment:HCGETUSER(@"userid")];
    }
    
    vc = [[HCMineAppView alloc] initWithFrame:CGRectMake(0, 0, self.centerView.frame.size.width, self.centerView.frame.size.height)];
    vc.delegate = self;
    [self.centerView addSubview:vc];
    
    // Do any additional setup after loading the view.
}

-(void)mineAppRefresh:(UITableView *)tableView_ {
    tableView__ = tableView_;
    [self.dataRequest postHC_MineAppointment:HCGETUSER(@"userid")];
}

-(void)dataRequesterFinish:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveDictionary:(NSDictionary *)dictionary {
    //    [WZNetWorkStatusManager dismiss:centerView];
    model = [[HCMineAppointmentModel alloc] initWithDictionary:dictionary error:nil];
    vc.model = model;
    [popLoading hidden];
    
    if (tableView__) {
        [tableView__ reloadData];
        [tableView__.mj_header endRefreshing];
    }
    
    NSLog(@"我的预约数据:%@",dictionary);
}

-(void)dataRequesterFail:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveErrorDictionary:(NSDictionary *)dictionary {
    //    [WZNetWorkStatusManager dismiss:centerView];
    [popLoading hidden];
    NSLog(@"我的预约数据请求失败");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
